package dados;

import java.util.List;

import negocio.MaquinaBean;

import org.hibernate.Session;

public class MaquinaDAO {

	public void armazenarMaquina(long grupo,String descricao) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		
		MaquinaBean m = new MaquinaBean();
		m.setGrupo(grupo);
		m.setDescricao(descricao);
		
		session.save(m);
		session.getTransaction().commit();
		}
	
	public void editarMaquina(MaquinaBean m,long grupo,String descricao){
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		m.setGrupo(grupo);
		m.setDescricao(descricao);
		session.update(m);
		session.getTransaction().commit();	
	}
	public List listar(){
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		List result = session.createQuery("from MaquinaBean").list();
		session.getTransaction().commit();
		return  result;
	}
	public void excluirMaquina(MaquinaBean m){
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		session.delete(m);
		session.getTransaction().commit();	
	}
	
}
